import random

from django.shortcuts import render

# Create your views here.
from django.http import JsonResponse

def ping(request):
    return JsonResponse({'status': 'pong'}, status=200)

from .models import Semester
def get_all_semesters(request):
    # 获取所有学期信息
    semesters = Semester.objects.all().values('semester_name')

    # 将查询结果转换为列表
    semesters_list = [i["semester_name"] for i in list(semesters)]

    # 返回JSON响应
    return JsonResponse({
        "code": 200,
        'data': {
            "num": random.randint(1, 100000),
            "semester_list": semesters_list
        },
        "msg": ""
    }, safe=False, status=200)
